home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / E-Z Progress Bar 1.0a / Environ.cp < prev    next >
Text File  |  1995-03-08  |  3KB  |  187 lines

  1. #define TrapMask 0x0800
  2. #include "Environ.h"
  3.  
  4. enum    { rNeeded=128, iSNeeded=1 };
  5.  
  6. long NumToolboxTraps()
  7. {
  8.     long trapTableSize;
  9.     
  10.     if (NGetTrapAddress(_InitGraf, ToolTrap) ==
  11.             NGetTrapAddress(0xAA6E, ToolTrap))
  12.         return(0x0200);
  13.     else if (!Gestalt(gestaltToolboxTable, &trapTableSize))
  14.         return (short) trapTableSize;
  15.     return (0x0400);
  16. }
  17. /*    Why/How NumToolboxTraps works (Inside Mac):
  18.     Macintosh Plus and Macintosh SE computers with system software prior
  19.     to System 7 masked their trap numbers with $1FF in the 
  20.     GetToolboxTrapAddress function so that the address of A-line instruction 
  21.     $AA6E (whether implemented or not) would be the same as A-line instruction $A86E,
  22.     which invokes the InitGraf routine 
  23.     
  24.     Which means that if _InitGraf (0xAA86E) points to the same address as 0xAA6E,
  25.     then it's system software prior to System 7, which means only 0x0200 traps available
  26. */
  27.  
  28. /*    Think Ref says Think C 5.0 and greater contain glue for Gestalt
  29.     for systems < 6.0.4 and the following can be obtained from Gestalt calls
  30.     for systems < 6.0.4:
  31.         gestaltVersion
  32.         gestaltMachineType
  33.         gestaltSystemVersion
  34.         gestaltProcessorType
  35.         gestaltFPUType
  36.         gestaltQuickdrawVersion
  37.         gestaltKeyBoardType
  38.         gestaltAppleTalkVersion
  39.         gestaltMMUType
  40.         gestaltPhysicalRamSize
  41.         gestaltLogicalRamSize
  42. */    
  43.  
  44. TrapType GetTrapType(short theTrap)
  45. {
  46.  
  47.     if ((theTrap & TrapMask) > 0)
  48.         return(ToolTrap);
  49.     else
  50.         return(OSTrap);
  51.  
  52. }
  53.  
  54. Boolean TrapAvailable(short theTrap)
  55. {
  56.  
  57.     TrapType    tType;
  58.  
  59.     tType = GetTrapType(theTrap);
  60.     if (tType == ToolTrap)
  61.         theTrap = theTrap & 0x07FF;
  62.     if (theTrap >= NumToolboxTraps())
  63.         theTrap = _Unimplemented;
  64.  
  65.     return (NGetTrapAddress(theTrap, tType) !=
  66.             NGetTrapAddress(_Unimplemented, ToolTrap));
  67. }
  68.  
  69.  
  70.  
  71. long    OSTableSize()
  72. {
  73.     return GenericGestalt(gestaltOSTable);
  74. }
  75.  
  76. long    SystemVersion()
  77. {
  78.     return GenericGestalt(gestaltSystemVersion);
  79. }
  80.  
  81. long    ROMSize()
  82. {
  83.     return GenericGestalt(gestaltROMSize);
  84. }
  85.  
  86. long    ROMVersion()
  87. {
  88.     return GenericGestalt(gestaltROMVersion);
  89. }
  90.  
  91. long    CPUType()
  92. {
  93.     return GenericGestalt(gestaltProcessorType);
  94. }
  95.  
  96. long    FPUType()
  97. {
  98.     return GenericGestalt(gestaltFPUType);
  99. }
  100.  
  101.  
  102. long    QDVersion()
  103. {
  104.     return GenericGestalt(gestaltQuickdrawVersion);
  105. }
  106.  
  107. long    RGBAvailable()
  108. {
  109.     return (TrapAvailable(_RGBForeColor));
  110. }
  111.  
  112. Boolean    ColorQD()
  113. {
  114.     return (QDVersion());
  115. }
  116.  
  117. Boolean    PopUps()
  118. {
  119.     if (!Gestalt(gestaltPopupAttr, nil))
  120.         return 1;
  121.     else
  122.         return 0;
  123. }
  124.  
  125. Boolean    OffScreenGWorlds()
  126. {
  127.     long result=QDVersion();
  128.     
  129.     if (result>=gestalt32BitQD)
  130.         return 1;
  131.     return 0;
  132. }
  133.     
  134. Boolean ColorScreen()
  135. {
  136.     return 0;
  137. }
  138. long    NumMonitors()
  139. {
  140.     return 0;
  141. }
  142.  
  143. long    GenericGestalt(long selectorCode)
  144. {
  145.     long theResult;
  146.     
  147.     if (!Gestalt(selectorCode, &theResult))
  148.         return theResult;
  149.     else
  150.         return 0;
  151. }
  152.  
  153. Boolean System7Savvy()
  154. {
  155.     long qdVersion, systemVersion;
  156.     if (TrapAvailable(_WaitNextEvent) && 
  157.         (!Gestalt(gestaltQuickdrawVersion, &qdVersion)) &&
  158.         (!Gestalt(gestaltPopupAttr, nil)) &&
  159.         (!Gestalt(gestaltSystemVersion, &systemVersion))
  160.         )
  161.         return ((qdVersion>=0x230) && (systemVersion>=0x700));
  162.     else
  163.         return 0;
  164. }
  165.  
  166. long    PhysicalRAM()
  167. {
  168.     return GenericGestalt(gestaltPhysicalRAMSize);
  169. }
  170.  
  171. long    LogicalRAM()
  172. {
  173.     return GenericGestalt(gestaltLogicalRAMSize);
  174. }
  175. long    LowMemorySize()
  176. {
  177.     return GenericGestalt(gestaltLowMemorySize);
  178. }
  179. long    KeyboardType()
  180. {
  181.     return GenericGestalt(gestaltKeyboardType);
  182. }
  183.  
  184. Boolean    WaitNextEventHere()
  185. {
  186.     return TrapAvailable(_WaitNextEvent);
  187. }